<?php
if (!defined('W_ROOT')) {
	exit();
}
$star = '<span style="color:red">*</span>';
$cat_class = $cat_image = $name = $cat_id = $desc = "";

$sql = "SELECT * FROM tblcategory WHERE id = $id";

$result = mysql_query($sql);
if(dbNumRows($result)){
	$row = mysql_fetch_assoc($result);

	$id = $row['id'];
	$name = $row['category_name'];
	$cat_id = $row['parent_id'];
	$cat_class = $row['cat_class'];
	$cat_image = $row['cat_image'];
	$desc = stripslashes($row['category_desc']);
}
$error = (isset($_GET['error']))?$_GET['error']:'';
	switch($error){
		case 'invalid_file':
			$error_msg = '<div class="warning">' . $lang['MSG_INVALID_FILE_TYPE'] . '</div>';
		break;
		case 'name_exist':
			$error_msg = '<div class="warning">' . $lang['MESSAGE_NAMEEXIST'] . '</div>';
		break;
		case 'file_size':
			$error_msg = '<div class="warning">' . $lang['MESSAGE_CATEGORY_FILE_SIZE'] . '</div>';
		break;
		case 'empty_file':
			$error_msg = '<div class="warning">' . $lang['MESSAGE_CATEGORY_FILE_EMPTY'] . '</div>';
		break;
	}
?>
<!--End of Validation-->
<div class="breadcrumb">
	<a href="<?php echo base_url_admin;?>"><?php echo $lang['HOME'];?></a>
	::<?php echo $lang['INSERT'];?>
</div>
<div class="box">
	<?php
		echo '<div class="message_contain">';
			echo @$error_msg;
		echo '</div>';
	 ?>
	<div class="heading">
		<h1><img src="../templates/image/category.png" alt="" />
			<?php echo $lang['CAT_MANAGE'];?>&nbsp;&nbsp;&nbsp;<span class="required">(*) all asterisks must be required!</span>
		</h1>
		<form action="<?php echo base_url_admin;?>/category/process.php?action=add" method="post" enctype="multipart/form-data" name="frmCategory" id="frmCategory">
		<div class="buttons">
			<input class="button" type="submit" name="btnsave" value="<?php echo $lang['SAVE'];?>" />&nbsp;&nbsp;&nbsp;
			<input class="button" type="reset" name="btnreset" value="<?php echo $lang['RESET'];?>" />&nbsp;&nbsp;&nbsp;
			<input class="button" type="button" name="btncancel" value="<?php echo $lang['CANCEL'];?>" onClick="javascript:window.history.back();" /><br/>
		</div>
	</div>
	<div class="content">
		<div class="row">
			<table align="center" cellpadding="5" cellspacing="5" width="99%">
				<tr>
					<td align="left"><?php echo $lang['MENU_CATEGORY'];?> </td>
					<td align="left" width="10">:</td>
					<td align="left">
						<select style="width:150px;" name="cate">
							<option value="0"><?php echo $lang['NONE'];?></option>
							<?php
								build_tree_drop_category($parent_id=0, $level=0, $id);
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td align="left" width="120"><?php echo $lang['CAT_NAME'];?> <font color="#FF0000">*</font></td>
					<td align="left" width="10">:</td>
					<td align="left"><input name="txtName" type="text" value="<?php echo @$name?>" style="width:100%" required /></td>
				</tr>
				<tr>
					<td align="left" valign="top">Class</td>
					<td valign="top" align="left">:</td>
					<td align="left">
						<input name="txtClass" type="text" value="<?php echo @$cat_class;?>" style="width:100%" />
						<input type="hidden" name="hidid" value="<?php echo @$id;?>" />
					</td>
				</tr>
				<tr>
					<td align="left" valign="top">Image (50 x 50) <?php echo (@$id == 0) ? '<font color="#FF0000">*</font>' : '';?></td>
					<td valign="top" align="left">:</td>
					<td align="left">
						<input name="txtimage" type="file" style="width:100%" <?php echo (@$id == 0) ? 'required' : '';?> />
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>
</div><!--<div class="row">-->